<?php 
/**
 * User: wjs
 * Date: 2020-2-12
 * time: 8:30
 * 
 */
namespace app\common;

/**
 * 公用日志记录类
 */
class Log
{    

    private $normal = array();

    private $debug = array();

    private $danger = array();

	public function __construct()
    {

    }


    /**
     * 直接写入但文件中
     */
    public function log($data='',$level='normal')
    {	
        if (is_array($data)) {
			$data = print_r($data,true);
    	}
		$data."\n";
        $years = date('Y-m-d');
    	switch ($level) {
    		case 'normal':
                $url = "/var/www/html/log/normalVending".$years."_log.txt";
    		break;
    		case 'debug':
                $url = "/var/www/html/log/debugVending".$years."_log.txt";
    		break;
    		case 'danger':
                $url = "/var/www/html/log/dangerVending".$years."_log.txt";
    		break;
    		default:
    			var_dump('log 参数错误');
                var_dump($data);
    		break;
    	}
        $dir_name = dirname($url);
        if(!file_exists($dir_name)){
            $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
        }
        $fp = fopen($url,"a");   
        fwrite($fp,date("Y-m-d H:i:s").'---->'.var_export($data,true)."\r\n");
        fclose($fp);
    }


    /**
     * 析构函数
     */
    function __destruct() {

   	}

}



